#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
  printf("O_RDONLY=%d,O_WRONLY=%d,O_RDWR=%d\n"
    ,O_RDONLY,O_WRONLY,O_RDWR);
  printf("O_CREAT=%d\n",O_CREAT);
  printf("O_APPEND=%d\n",O_APPEND);
  printf("O_TRUNC=%d\n",O_TRUNC);

  int fd = open("a.txt",O_CREAT|O_RDWR|O_TRUNC,0666);
  if(fd == -1) perror("open") ,exit(-1);
  printf("open file\n");


  char buf[100] = {};
  int read_len = read(fd,buf,100);
  if(read_len == -1)
	perror("read") , exit(-1);
  printf("size = %d , content = %s",read_len,buf);

  int write_len = write(fd,"continue",strlen("continue"));
  if(write_len == -1)
	perror("write") , exit(-1);
  printf("the written size = %d\n",write_len);
  close(fd);
}
